import request from '@/utils/request.js';

// 小程序登录
export function loginByMp(params) {
  return request({
    url: '/auth/oauth2/token',
    method: 'post',
    headers: {
      Authorization: 'Basic dGlrdG9rOnRpa3Rvaw==',
      'Client-Toc': 'Y',
    },
    params: {
      grant_type: 'tiktok',
      ...params,
      scope: 'server',
    },
  });
}

/**
 * 发送验证码
 * @param  mobile
 */
export function sendMobile(mobile) {
  return request({
    url: `/app/mobile/${mobile}`,
    method: 'get',
  });
}
/**
 * 获取当前登录的用户信息
 * @returns {AxiosPromise}
 */
export function getUserInfo() {
  return request({
    url: '/app/appuser/info',
    method: 'get',
  });
}
/**
 * 获取规则内容
 * @param {Object}
 */
export function getRuleInfo(code) {
  return request({
    url: `/core/displayfile/code/${code}`,
    method: 'get',
  });
}
// 获取字典
export function getDictData(type) {
  return request({
    url: `/admin/dict/type/${type}`,
    method: 'get',
  });
}
/**
 * 获取抖音用户的OpenId
 */
export function getTikTokOpenId(code) {
  return request({
    url: `/app/applet/tiktok/${code}`,
    method: 'get',
  });
}

//退出登录
export function userExitLogin() {
  return request({
    url: '/auth/token/logout',
    method: 'delete',
    headers: {
      'Content-Type': 'application/json',
    },
  });
}